package com.linsir.file.util.filter;

import com.linsir.core.code.BaseCode;
import com.linsir.file.exception.FileException;
import com.linsir.file.util.FileCommonUtils;
import org.springframework.web.multipart.MultipartFile;


/**
 * @author ：linsir
 * @date ：Created in 2022/9/15 0:36
 * @description：文件类型过滤
 * @modified By：
 * @version:
 */
public class FileTypeFilter {

    /**不能够上传的文件后缀*/
    private static String[] forbidType = {"jsp","php"};



    public static void fileTypeFilter(MultipartFile file) throws Exception {
        String suffix = FileCommonUtils.getFileType(file);
        for (String type : forbidType) {
            if (type.contains(suffix)) {
                throw new FileException(BaseCode.FILE_TYPE_ERROR,"上传失败，文件类型异常：" + suffix);
            }
        }
    }





}
